# 定义元组
t1 = (1, "Hello", True)
t2 = ()
t3 = tuple()
print(f"t1的类型是{type(t1)},内容是:{t1}")
print(f"t2的类型是{type(t2)},内容是:{t2}")
print(f"t3的类型是{type(t3)},内容是:{t3}")

# 定义单个元素的元组
t4 = ("hello",)
print(f"t4的类型是{type(t4)},内容是:{t4}")

# 定义一个嵌套元组
t5 = ((1, 2, 3), (4, 5, 6))
print(t5[0][0], t5)

# 下标索引取出内容
print(t5[1][2])

# index
t6 = (1, 2, 3)
index = t6.index(1)
print(index)

# count
t7 = (1, 2, 3, 2, 2, 3, 3, 3, 3)
num = t7.count(2)
print(f"2有{num}个")

# len
t8 = (1, 2, 3, 2, 2, 3, 3, 3, 3)
num2 = len(t8)
print(f"t8中共有{num2}个元素")


# 元组的遍历（while)
index = 0
while index < len(t8):
    print(f"t8中的元素有：{t8[index]}")
    index += 1


# 元组的遍历（for)
index = 0
for i in t7:
    print(f"t7中的元素有：{i}")



# 修改元组内的list内容
list1 = [1, 2, 3]
t9 = (1, 2, 3, list1)
print(t9)
t9[3][1] = 'best'
print(t9)
t9[3].append("hello")
print(t9)
